import json

import dashscope,json
from django.conf import settings
from django.http import HttpResponse
from dashscope.audio.tts_v2 import VoiceEnrollmentService, SpeechSynthesizer

dashscope.api_key = settings.ALIYUN_KEY

def list(req):
    try:
        page_index = req.GET.get('page',1)
        page_size = req.GET.get('size',10)
        service = VoiceEnrollmentService()
        voice_list = service.list_voices(None,page_index,page_size)
        return HttpResponse("{0}".format(voice_list))
    except Exception as e:
        return HttpResponse(json.dumps({'code': 1, 'msg': f"{e}"}))
def delete(req):
    voice_id = req.GET.get('voice_id','')
    service = VoiceEnrollmentService()
    try:
        service.delete_voice(voice_id)
        return HttpResponse(json.dumps({"code":0,"msg":"ok"}))
    except Exception as e:
        return HttpResponse(json.dumps({'code': 1, 'msg': f"{e}"}))

def sy_voice_list(req) :
    data = [
        {
            "people": "龙婉",
            "model": "cosyvoice-v1",
            "parameter": "longwan",
            "scenarios": "语音助手、导航播报、聊天数字人",
            "lang": "中文普通话"
        },
        {
            "people": "龙橙",
            "model": "cosyvoice-v1",
            "parameter": "longcheng",
            "scenarios": "语音助手、导航播报、聊天数字人",
            "lang": "中文普通话"
        },
        {
            "people": "龙华",
            "model": "cosyvoice-v1",
            "parameter": "longhua",
            "scenarios": "语音助手、导航播报、聊天数字人",
            "lang": "中文普通话"
        },
        {
            "people": "龙小淳",
            "model": "cosyvoice-v1",
            "parameter": "longxiaochun",
            "scenarios": "语音助手、导航播报、聊天数字人",
            "lang": "中文+英文"
        },
        {
            "people": "龙小夏",
            "model": "cosyvoice-v1",
            "parameter": "longxiaoxia",
            "scenarios": "语音助手、聊天数字人",
            "lang": "中文"
        },
        {
            "people": "龙小诚",
            "model": "cosyvoice-v1",
            "parameter": "longxiaocheng",
            "scenarios": "语音助手、导航播报、聊天数字人",
            "lang": "中文+英文"
        },
        {
            "people": "龙小白",
            "model": "cosyvoice-v1",
            "parameter": "longxiaobai",
            "scenarios": "聊天数字人、有声书、语音助手",
            "lang": "中文"
        },
        {
            "people": "龙老铁",
            "model": "cosyvoice-v1",
            "parameter": "longlaotie",
            "scenarios": "新闻播报、有声书、语音助手、直播带货、导航播报",
            "lang": "中文东北口音"
        },
        {
            "people": "龙书",
            "model": "cosyvoice-v1",
            "parameter": "longshu",
            "scenarios": "有声书、语音助手、导航播报、新闻播报、智能客服",
            "lang": "中文"
        },
        {
            "people": "龙硕",
            "model": "cosyvoice-v1",
            "parameter": "longshuo",
            "scenarios": "语音助手、导航播报、新闻播报、客服催收",
            "lang": "中文"
        },
        {
            "people": "龙婧",
            "model": "cosyvoice-v1",
            "parameter": "longjing",
            "scenarios": "语音助手、导航播报、新闻播报、客服催收",
            "lang": "中文"
        },
        {
            "people": "龙妙",
            "model": "cosyvoice-v1",
            "parameter": "longmiao",
            "scenarios": "客服催收、导航播报、有声书、语音助手",
            "lang": "中文"
        },
        {
            "people": "龙悦",
            "model": "cosyvoice-v1",
            "parameter": "longyue",
            "scenarios": "语音助手、诗词朗诵、有声书朗读、导航播报、新闻播报、客服催收",
            "lang": "中文"
        },
        {
            "people": "龙媛",
            "model": "cosyvoice-v1",
            "parameter": "longyuan",
            "scenarios": "有声书、语音助手、聊天数字人",
            "lang": "中文"
        },
        {
            "people": "龙飞",
            "model": "cosyvoice-v1",
            "parameter": "longfei",
            "scenarios": "会议播报、新闻播报、有声书",
            "lang": "中文"
        },
        {
            "people": "龙杰力豆",
            "model": "cosyvoice-v1",
            "parameter": "longjielidou",
            "scenarios": "新闻播报、有声书、聊天助手",
            "lang": "中文+英文"
        },
        {
            "people": "龙彤",
            "model": "cosyvoice-v1",
            "parameter": "longtong",
            "scenarios": "有声书、导航播报、聊天数字人",
            "lang": "中文"
        },
        {
            "people": "龙祥",
            "model": "cosyvoice-v1",
            "parameter": "longxiang",
            "scenarios": "新闻播报、有声书、导航播报",
            "lang": "中文"
        },
        {
            "people": "Stella",
            "model": "cosyvoice-v1",
            "parameter": "loongstella",
            "scenarios": "语音助手、直播带货、导航播报、客服催收、有声书",
            "lang": "中文+英文"
        },
        {
            "people": "Bella",
            "model": "cosyvoice-v1",
            "parameter": "loongbella",
            "scenarios": "语音助手、客服催收、新闻播报、导航播报",
            "lang": "中文"
        }
    ]
    return HttpResponse(json.dumps(data))